﻿using System.Windows;
using System.Windows.Controls;
using MyFinanceManager.Objects;
using System.Diagnostics;

namespace MyFinanceManager.PC
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Window1"/> class.
        /// </summary>
        public Window1()
        {
            try
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
                InitializeComponent();
                this.DataContext = Database.Db;
            }
            catch
            {
                Debugger.Break();
            }
        }

        #region Eventhandling
        /// <summary>
        /// Handles the SelectionChanged event of the Earnings control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void Earnings_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.postingRecordViewer.DataContext = this.earnings.SelectedItem;
        }

        /// <summary>
        /// Handles the SelectionChanged event of the Expenses control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void Expenses_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.postingRecordViewer.DataContext = this.expenses.SelectedItem;
        }

        /// <summary>
        /// Handles the SelectionChanged event of the TabControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.startpage != null)
                this.startpage.Visibility = Visibility.Hidden;
            if (this.catViewer != null)
                this.catViewer.Visibility = Visibility.Hidden;

            if (this.postingRecordViewer != null && this.graphViewer != null)
            {
                switch (this.outlookControl.SelectedIndex)
                {
                    case 0: //Ausgaben
                        this.postingRecordViewer.Visibility = Visibility.Visible;
                        this.graphViewer.Visibility = Visibility.Hidden;
                        break;
                    case 1: //Einnahmen
                        this.postingRecordViewer.Visibility = Visibility.Visible;
                        this.graphViewer.Visibility = Visibility.Hidden;
                        break;
                    case 2: // Übersicht
                        this.postingRecordViewer.Visibility = Visibility.Hidden;
                        this.graphViewer.Visibility = Visibility.Visible;
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// Handles the Click event of the btCat control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btCat_Click(object sender, RoutedEventArgs e)
        {
            this.graphViewer.Visibility = Visibility.Hidden;
            this.catViewer.Refresh();
            this.catViewer.Visibility = Visibility.Visible;
        }
        #endregion

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            RepositoryCenter.Repositoy.Save();
        }
    }
}
